package DynamicProgrammingPackage;

public class canPartition_ {
    public static void main(String[] args) {
        int[] value = new int[]{10,15,25};
        int[] weight = new int[]{1,3,4};
    }
    // 1. dp[i]表示
    public boolean canPartition(int[] nums) {
        int sum = 0;
        for (int num : nums) {
            sum += num;
        }
        if (sum % 2 != 0){
            return false;
        }
        int target = sum / 2;
        int[] dp = new int[target + 1];
        for (int i = 1; i <= target; i++) {
            for (int j = target; j >= nums[i]; j--) {
                dp[j] = Math.max(dp[j], dp[j - nums[i]] + nums[i]);
            }
        }
        return sum - dp[target] - dp[target] == 0 ? true : false;
    }
}

